#include "GetArgsTestSuitie.h"
#include <cstddef>
#include <cstdint>
#if __cplusplus >= 201402L

#    include "LoggerNew.h"
using namespace xncc;
TEST_F(GetArgsTestSuitie, getArgsSizeNoParams)
{
    static constexpr char testStr[] = "tests string";
    auto constexpr rets             = parseFormatStr<getFormatParamsCount(testStr)>(testStr);
    EXPECT_EQ(getArgsSize(rets), 0);
}

TEST_F(GetArgsTestSuitie, getArgsSizeOneParams)
{
    static constexpr char testStr[] = "tests string %d";
    auto constexpr rets             = parseFormatStr<getFormatParamsCount(testStr)>(testStr);
    EXPECT_EQ(getArgsSize(rets, 1), sizeof(int64_t));
}

TEST_F(GetArgsTestSuitie, getArgsSizeTwoParams)
{
    static constexpr char testStr[] = "%u tests string %d";
    auto constexpr rets             = parseFormatStr<getFormatParamsCount(testStr)>(testStr);
    EXPECT_EQ(getArgsSize(rets, 1U, 1000), sizeof(int64_t) + sizeof(uint64_t));
}

TEST_F(GetArgsTestSuitie, getArgsSizeStringParams)
{
    static constexpr char testStr[] = "%u tests string %d %s";
    const std::string     data      = "ahhhahahah";
    auto constexpr rets             = parseFormatStr<getFormatParamsCount(testStr)>(testStr);
    EXPECT_EQ(getArgsSize(rets, 1U, 1000, data.c_str()),
              sizeof(int64_t) + sizeof(uint64_t) + sizeof(int) + data.size());
}

TEST_F(GetArgsTestSuitie, getArgsSizeCppStringParams)
{
    static constexpr char testStr[] = "%u tests string %d %s";
    const std::string     data      = "ahhhahahah";
    auto constexpr rets             = parseFormatStr<getFormatParamsCount(testStr)>(testStr);
    EXPECT_EQ(getArgsSize(rets, 1U, 1000, data.c_str()),
              sizeof(int64_t) + sizeof(uint64_t) + sizeof(int) + data.size());
}

struct TestObj
{
    int  a = 1;
    int  b = 2;
    int  c = 3;
    void ToString(std::ostringstream& oss)
    {
        oss << "a=" << a << " b=" << b << " c=" << c << " ";
    }
};

TEST_F(GetArgsTestSuitie, getArgsSizeFunction)
{
    static constexpr char testStr[] = "tests string %F";
    auto constexpr rets             = parseFormatStr<getFormatParamsCount(testStr)>(testStr);
    TestObj                      obj;
    static constexpr std::size_t funcSize = sizeof(FunctionObject<TestObj, decltype(&TestObj::ToString)>);
    EXPECT_GT(getArgsSize(rets, FUNCTION_OBJECT(obj, &TestObj::ToString)), funcSize);
}

TEST_F(GetArgsTestSuitie, getArgsSizeConstString)
{
    static constexpr char testStr[] = "tests string %S";
    auto constexpr rets             = parseFormatStr<getFormatParamsCount(testStr)>(testStr);
    EXPECT_EQ(getArgsSize(rets, "test string"_s), sizeof(void*));
}
#endif